package com.lv.dhart.adapters;

import android.annotation.SuppressLint;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.lv.dhart.R;
import com.lv.dhart.beans.market.OnePriceOrders;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by jianghejie on 15/11/26.
 */
public class MyAdapter extends RecyclerView.Adapter<MyAdapter.ViewHolder> {


    public void setClickCallBack(ItemClickCallBack clickCallBack) {
        this.clickCallBack = clickCallBack;
    }


    public interface ItemClickCallBack {
        void onItemClick(int pos);
    }

    public ArrayList<OnePriceOrders.DataDTO.ListDTO> datas;
    private ItemClickCallBack clickCallBack;

    public MyAdapter(ArrayList<OnePriceOrders.DataDTO.ListDTO> datas) {
        this.datas = datas;
    }

    //创建新View，被LayoutManager所调用
    @Override
    public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
        View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.market_dc_list_item, viewGroup, false);
        return new ViewHolder(view);
    }

    //将数据与界面进行绑定的操作
    @Override
    public void onBindViewHolder(ViewHolder viewHolder, @SuppressLint("RecyclerView") final int position) {
        viewHolder.marketDcName.setText(datas.get(position).getNftName());
        viewHolder.marketDcSellAmount.setText("挂单量：" + datas.get(position).getOnSaleNum());
        viewHolder.marketDcSellPriceLowest.setText("地板价：" + String.valueOf(datas.get(position).getFloorPrice()));
        viewHolder.marketDcPrice.setText("发行价：" + String.valueOf(datas.get(position).getIssuePrice()));

        //通过图片加载器实现圆角，你也可以自己使用圆角的imageview，实现圆角的方法很多，自己尝试哈
        Glide.with(viewHolder.marketDcImg)
                .load(datas.get(position).getImage())
                .thumbnail(Glide.with(viewHolder.marketDcImg).load(R.drawable.loading))
                .skipMemoryCache(true).diskCacheStrategy(DiskCacheStrategy.NONE)
                .apply(RequestOptions.bitmapTransform(new RoundedCorners(30)))
                .into(viewHolder.marketDcImg);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position, List<Object> payloads) {
        super.onBindViewHolder(holder, position, payloads);
    }

    //获取数据的数量
    @Override
    public int getItemCount() {
        return datas.size();
    }

    //自定义的ViewHolder，持有每个Item的的所有界面元素
    public static class ViewHolder extends RecyclerView.ViewHolder {

        private ImageView marketDcImg;
        private TextView marketDcName;
        private TextView marketDcPrice;
        private TextView marketDcSellAmount;
        private TextView marketDcSellPriceLowest;

        public ViewHolder(View view) {
            super(view);
            marketDcImg = view.findViewById(R.id.market_dc_img);
            marketDcName = view.findViewById(R.id.market_dc_name);
            marketDcPrice = view.findViewById(R.id.market_dc_price);
            marketDcSellAmount = view.findViewById(R.id.market_dc_sell_amount);
            marketDcSellPriceLowest = view.findViewById(R.id.market_dc_sell_price_lowest);
        }
    }
}





















